<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *报名管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$manage_op=array('confirm','cancel','agree','disagree');
if(in_array($_RQ['op'],$manage_op)){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择报名订单！','error');
	}
}
$return=array();
$tabs=array(
	array('op'=>'list','title'=>'报名列表'),
);
$return['status']=array('0'=>'未支付','1'=>'已支付','2'=>'已报名','3'=>'已取消','4'=>'已完成');
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	$data['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['realname'])){
		$data['realname like']='%'.trim($_RQ['realname']).'%';
		$user_id=pdo_getcolumn('core_members',$data,'id');
		$params['user_id']=intval($user_id);
		$return['params']['realname']=$_RQ['realname'];
	}
	$data2['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['activity_title'])){
		$data2['title like']='%'.trim($_RQ['activity_title']).'%';
		$activity_id=pdo_getcolumn('jy_cmsactivity_list',$data2,'id');
		$params['activity_id']=intval($activity_id);
		$return['params']['activity_title']=$_RQ['activity_title'];
	}
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
		
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','name','mobile','remark','uniacid','user_id','activity_id','ordersn','money','pay','status','createtime');
	$list=pdo_getslice('jy_cmsactivity_order',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['activity_title']=pdo_getcolumn('jy_cmsactivity_list',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['activity_id']),'title');
			$item['member']=cfc('core')->member_show($item['user_id']);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>true,'delall'=>true,'list'=>array(
			array('name'=>'activity_title','title'=>'活动名称','type'=>'string'),
			array('name'=>'member','title'=>'用户会员信息','type'=>'member'),
			array('name'=>'name','title'=>'预订人姓名','type'=>'string'),
			array('name'=>'mobile','title'=>'联系电话','type'=>'string'),
			array('name'=>'remark','title'=>'备注','type'=>'string'),
			array('name'=>'money','title'=>'金额','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
			array('name'=>'createtime','title'=>'报名时间','type'=>'time'),
		)),
		'search'=>array(
			array('name'=>'realname','title'=>'用户姓名','type'=>'string','width'=>'15'),
			array('name'=>'activity_title','title'=>'活动名称','type'=>'string','width'=>'15'),
			array('name'=>'status','title'=>'活动状态','type'=>'radio','width'=>'15','options'=>'status'),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}

//确认报名操作
if($_RQ['op']=='confirm'){
	if($_RQ['id']){
	
		pdo_update('jy_cmsactivity_order',array('status'=>'2'),array('id'=>$_RQ['id'],'uniacid'=>$_SESSION['uniacid']));
		
	}
	exi('确认报名成功！');
}
//取消报名操作
if($_RQ['op']=='cancel'){
	if($_RQ['id']){
	
		pdo_update('jy_cmsactivity_order',array('status'=>'3'),array('id'=>$_RQ['id'],'uniacid'=>$_SESSION['uniacid']));
		
	}
	exi('取消报名成功！');
}
//同意退款
if($_RQ['op']=='agree'){
	if($_RQ['id']){
	
		pdo_update('jy_cmsactivity_order',array('status'=>'6'),array('id'=>$_RQ['id'],'uniacid'=>$_SESSION['uniacid']));
		
	}
	exi('已同意退款申请！');
}
//拒绝退款操作
if($_RQ['op']=='disagree'){
	if($_RQ['id']){
	
		pdo_update('jy_cmsactivity_order',array('status'=>'7'),array('id'=>$_RQ['id'],'uniacid'=>$_SESSION['uniacid']));
		
	}
	exi('已拒绝退款申请！');
}

if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_cmsactivity_order',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}